package com.chinda.common.filter;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.servlet.*;
import java.io.IOException;

/**
 * @author Wang Chinda
 * @date 2021/6/5
 */
@Slf4j
@Component
public class GlobalExceptionFilter implements Filter {

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        try {
            chain.doFilter(request, response);
        } catch (Exception e) {
            log.error("An exception occurred in the filter.", e);
            request.getRequestDispatcher("/filter/exception").forward(request, response);
        }
    }
}
